package com.saohuobang.test.controller;

import com.saohuobang.test.model.core.APIResponse;
import com.saohuobang.test.service.JMXConfigService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;

/**
 * 作者 yaohua.liu
 * 日期 2015-11-24 11:32
 * 包名 com.saohuobang.test.controller
 * 说明 日志等级动态控制接口
 */
@RequestMapping(value = "/backdoor/log")
@Controller
public class JMXConfigController extends AbstractController{

    @Resource
    private JMXConfigService jMXConfigService;

    @RequestMapping(value = "/startJMXConfig.api")
    @ResponseBody
    public Object startJMXConfig(@RequestParam(required = false) String port) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
        String result = jMXConfigService.startJMXConfig(port);
        return APIResponse.returnSuccess(result);
    }

    @RequestMapping(value = "/stopJMXConfig.api")
    @ResponseBody
    public Object stopJMXConfig() throws Exception {
        String result = jMXConfigService.stopJMXConfig();
        return APIResponse.returnSuccess(result);
    }
}
